home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-28 | 11.2 KB | 365 lines | [TEXT/CWIE] |
- /* ----------------------------------------------------------------------
-
- Launcher
-
- Written by: Paul Celestin
-
- 950314 - work begins on the project
- 950321 - work continues
- 950808 - added ability to open ConfigPPP
- 951213 - fixed (maybe) crashing bug when launching apps
-
- ---------------------------------------------------------------------- */
-
-
- /* ----------------------------------------------------------------------
- includes
- ---------------------------------------------------------------------- */
-
- #include "the_defines.h"
- #include "the_globals.h"
- #include "the_prototypes.h"
- #include "pppcontrol.h"
-
- Boolean gDone,
- gWNEImplemented,
- gInBackground;
- int gNumApps;
- EventRecord gTheEvent;
- MenuHandle gAppleMenu,
- gFileMenu;
- WindowPtr gTheWindow;
- PixPatHandle gPixPat;
- ProcessSerialNumber gMailApp,
- gNewsApp,
- gFTPApp,
- gWebApp,
- gTelnetApp;
-
- /* ----------------------------------------------------------------------
- main - here is where it all began...
- ---------------------------------------------------------------------- */
- void main()
- {
- InitToolBox();
- InitMenuBar();
- MainLoop();
- ExitToShell();
- }
-
-
- /* ----------------------------------------------------------------------
- InitToolBox
- ---------------------------------------------------------------------- */
- void InitToolBox()
- {
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- }
-
-
- /* ----------------------------------------------------------------------
- InitMenuBar
- ---------------------------------------------------------------------- */
- void InitMenuBar()
- {
- Handle myMenuBar;
-
- myMenuBar = GetNewMBar(MENU_BASE_ID);
- if (myMenuBar == NIL)
- SysBeep(1);
- else
- SetMenuBar(myMenuBar);
-
- gAppleMenu = GetMHandle(MENU_APPLE_ID);
- if (gAppleMenu == NIL)
- SysBeep(1);
- else
- AddResMenu(gAppleMenu,'DRVR');
-
- gFileMenu = GetMHandle(MENU_FILE_ID);
- if (gFileMenu == NIL)
- SysBeep(1);
-
- DrawMenuBar();
- }
-
-
- /* ----------------------------------------------------------------------
- MainLoop
- ---------------------------------------------------------------------- */
- void MainLoop()
- {
- RgnHandle cursorRgn;
- Boolean gotEvent;
- WindowRecord *myWinRecord;
- Rect myWinRect;
- Str255 myTitle;
-
- gInBackground = false;
-
- cursorRgn = NewRgn();
-
- gWNEImplemented = (NGetTrapAddress(WNE_TRAP_NUM,ToolTrap) !=
- NGetTrapAddress(UNIMPL_TRAP_NUM,ToolTrap));
-
- gPixPat = GetPixPat(SYSTEM_PPAT);
-
- myWinRect = qd.screenBits.bounds;
- myWinRecord = NIL;
- gTheWindow =
- NewCWindow(myWinRecord,&myWinRect,"\p",FALSE,plainDBox,(WindowPtr)-1L,FALSE,0L);
-
- if (gTheWindow)
- {
- DrawButtons();
- ShowWindow(gTheWindow);
- DoUpdate();
-
- gDone = false;
-
- while (gDone == false)
- {
- if (gWNEImplemented)
- gotEvent = WaitNextEvent(everyEvent,&gTheEvent,MIN_SLEEP,cursorRgn);
- else
- {
- SystemTask();
- gotEvent = GetNextEvent(everyEvent,&gTheEvent);
- }
-
- if (gotEvent)
- Do();
- }
- QuitAllApps();
- }
- }
-
-
- /* ------------------------------------------------ enuChoice);
- break;
- case inSysWindow:
- SystemClick(&gTheEvent,window);
- break;
- case inContent:
- if (window != FrontWindow())
- SelectWindow(window);
- else
- {
- p = gTheEvent.where;
- GlobalToLocal(&p);
- DoWindow(p);
- }
- break;
- default:
- break;
- }
- }
-
- /* ----------------------------------------------------------------------
- DoMenu
- ---------------------------------------------------------------------- */
- void DoMenu(menuChoice)
- long int menuChoice;
- {
- int theMenu;
- int theItem;
-
- if (menuChoice != 0)
- {
- theMenu = HiWord(menuChoice);
- theItem = LoWord(menuChoice);
- switch (theMenu)
- {
- case MENU_APPLE_ID:
- DoMenuApple(theItem);
- break;
- case MENU_FILE_ID:
- DoMenuFile(theItem);
- break;
- default:
- break;
- }
- HiliteMenu(0);
- }
- }
-
- /* ----------------------------------------------------------------------
- DoWindow
- ---------------------------------------------------------------------- */
- void DoWindow(Point p)
- {
- short choice;
- ControlHandle control;
- CursHandle theCursor;
-
- if (FindControl(p,gTheWindow,&control))
- {
- if (TrackControl(control,p,NIL))
- {
- theCursor = GetCursor(4);
- HLock((Handle)theCursor);
- SetCursor(*theCursor);
- HUnlock((Handle)theCursor);
-
- choice = GetCtlValue(control);
-
- switch (choice)
- {
- case PPP_CONTROL:
- DoPPP();
- break;
- case MAIL_CONTROL:
- DoMail();
- break;
- case NEWS_CONTROL:
- DoNews();
- break;
- case FTP_CONTROL:
- DoFTP();
- break;
- case WEB_CONTROL:
- DoWeb();
- break;
- case TELNET_CONTROL:
- DoTelnet();
- break;
- default:
- break;
- }
- }
- }
- }
-
-
- /* ----------------------------------------------------------------------
- DoPPP
- ---------------------------------------------------------------------- */
- void DoPPP()
- {
- short vRefNum;
- long dirID;
- FSSpec theApp;
- OSErr myErr;
-
- myErr = FindFolder(kOnSystemDisk, kControlPanelFolderType,
- kDontCreateFolder, &vRefNum, &dirID);
- if (myErr != noErr)
- {
- SysBeep(1);
- return;
- }
- myErr = LocateFile(TYPE_CDEV, CREATOR_PPP, vRefNum, &theApp);
- if (myErr != noErr)
- {
- SysBeep(1);
- return;
- }
- myErr = OpenCP(theApp, CREATOR_PPP);
- if (myErr != noErr)
- {
- SysBeep(1);
- return;
- }
- }
-
-
- /* ----------------------------------------------------------------------
- DoMail
- ---------------------------------------------------------------------- */
- void DoMail()
- {
- FSSpec theApp;
-
- if (LocateFile('APPL', CREATOR_MAIL, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gMailApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- DoNews
- ---------------------------------------------------------------------- */
- void DoNews()
- {
- FSSpec theApp;
-
- if (!pppup())
- pppopen();
- if (LocateFile('APPL', CREATOR_NEWS, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gNewsApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- DoFTP
- ---------------------------------------------------------------------- */
- void DoFTP()
- {
- FSSpec theApp;
-
- if (!pppup())
- pppopen();
- if (LocateFile('APPL', CREATOR_FTP, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gFTPApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- DoWeb
- ---------------------------------------------------------------------- */
- void DoWeb()
- {
- FSSpec theApp;
-
- if (!pppup())
- pppopen();
- if (LocateFile('APPL', CREATOR_WEB, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gWebApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- DoTelnet
- ---------------------------------------------------------------------- */
- void DoTelnet()
- {
- FSSpec theApp;
-
- if (!pppup())
- pppopen();
- if (LocateFile('APPL', CREATOR_TELNET, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gTelnetApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- QuitAllApps
- ---------------------------------------------------------------------- */
- void QuitAllApps()
- {
- CursHandle theCursor;
-
- theCursor = GetCursor(4);
- HLock((Handle)theCursor);
- SetCursor(*theCursor);
- HUnlock((Handle)theCursor);
-
- QuitIt(&gMailApp);
- QuitIt(&gNewsApp);
- QuitIt(&gFTPApp);
- QuitIt(&gWebApp);
- QuitIt(&gTelnetApp);
- if (pppup())
- pppclose(1);
- }